<template>
<!--  <ContentWrap>-->
<!--    &lt;!&ndash; 搜索工作栏 &ndash;&gt;-->
<!--    <el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true">-->
<!--      <el-form-item :label="t('mentorPickReviewScene.fields.isVote')" prop="isVote">-->
<!--        <el-select-->
<!--          v-model="queryParams.isVote"-->
<!--          clearable-->
<!--          :placeholder="t('mentorPickReviewScene.fields.isVote')"-->
<!--          style="width: 120px"-->
<!--        >-->
<!--          <el-option-->
<!--            v-for="status in voteStatusOptions"-->
<!--            :label="status.label"-->
<!--            :value="status.value"-->
<!--            :key="status.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button @click="handleQuery">-->
<!--          <Icon icon="ep:search" class="mr-5px" />{{ t('common.search') }}-->
<!--        </el-button>-->
<!--        <el-button @click="resetQuery">-->
<!--          <Icon icon="ep:refresh" class="mr-5px" />{{ t('common.reset') }}-->
<!--        </el-button>-->
<!--      </el-form-item>-->
<!--    </el-form>-->
<!--  </ContentWrap>-->

  <!-- 列表 -->
  <ContentWrap>
    <vxe-toolbar ref="toolbarRef" custom />
    <vxe-table
      id="iPickBatch-table"
      ref="tableRef"
      v-loading="loading"
      :data="list"
      stripe
      :custom-config="vxeTableConfig"
      :column-config="{ resizable: true }"
      :size="vxeTableSize"
    >
      <vxe-column :title="t('common.index')" type="seq" field="seq" width="60" align="center" />
      <vxe-column
        :title="t('mentorPickReviewScene.fields.nickName')"
        field="nickName"
        align="center"
        show-header-overflow
        show-overflow
        min-width="50"
      />
      <vxe-column
        :title="t('mentorPickReviewScene.fields.deptName')"
        field="deptName"
        align="center"
        show-header-overflow
        show-overflow
        min-width="120"
      />
      <vxe-column
        :title="t('mentorPickReviewScene.fields.applyMajor')"
        field="applyMajor"
        align="center"
        show-header-overflow
        show-overflow
        min-width="120"
      />
      <vxe-column
        :title="t('mentorPickReviewScene.fields.highestDegree')"
        field="highestDegree"
        align="center"
        show-header-overflow
        show-overflow
        min-width="80"
      />
      <vxe-column
        :title="t('mentorPickReviewScene.fields.isVote')"
        field="isVote"
        align="center"
        show-header-overflow
        show-overflow
        min-width="60"
      >
        <template #default="{ row }">
          <el-tag disable-transitions v-if="row.isVote === 0" type="warning">
            {{ t('mentorPickReviewScene.voteStatus.unVote') }}
          </el-tag>
          <el-tag disable-transitions v-if="row.isVote === 1" type="success">
            {{ t('mentorPickReviewScene.voteStatus.agree') }}
          </el-tag>
          <el-tag disable-transitions v-if="row.isVote === 2" type="danger">
            {{ t('mentorPickReviewScene.voteStatus.disagree') }}
          </el-tag>
        </template>
      </vxe-column>
      <vxe-column
        :title="t('mentorPickReviewScene.fields.applicationFormUrl')"
        field="applicationFormUrl"
        align="center"
        show-header-overflow
        show-overflow
        min-width="60"
      >
        <template #default="{ row }">
          <FileObjectDownloadList :file-json-list="row.applicationFormUrl" />
        </template>
      </vxe-column>
      <vxe-column
        :title="t('mentorPickReviewScene.fields.appendixUrl')"
        field="appendixUrl"
        align="center"
        show-header-overflow
        show-overflow
        min-width="60"
      >
        <template #default="{ row }">
          <FileObjectDownloadList :file-json-list="row.appendixUrl" />
        </template>
      </vxe-column>
      <vxe-column
        :title="t('common.operate')"
        field="operator"
        align="center"
        fixed="right"
        width="200"
      >
        <template #default="{ row }">
          <el-button v-if="row.isVote === 0" link type="primary" @click="handleClick(row)">
            {{ t('mentorPickReviewScene.operate.vote') }}
          </el-button>
          <el-button v-else link type="success">
            {{ t('mentorPickReviewScene.operate.voted') }}
          </el-button>
        </template>
      </vxe-column>
    </vxe-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
  <!-- 投票弹窗 -->
  <MentorPickReviewVote ref="mentorPickReviewVoteRef" @voted="getList" />
</template>

<script setup lang="ts">
import { MentorPickReviewApi, MentorPickReviewSceneVO } from '@/api/recruit/mentorPickReview'
import type { VxeTablePropTypes, VxeToolbarInstance, VxeTableInstance } from 'vxe-table'
import { useAppStore } from '@/store/modules/app'
import FileObjectDownloadList from '@/components/FileObjectDownload/list.vue'
import MentorPickReviewVote from './components/MentorPickReviewVote.vue'

/** 导师遴选评审现场 申请列表 */
defineOptions({ name: 'MentorPickReviewScene' })

const { t } = useI18n() // 国际化
const route = useRoute() // 路由

const toolbarRef = ref<VxeToolbarInstance>()
const tableRef = ref<VxeTableInstance>()
const mentorPickReviewVoteRef = ref<InstanceType<typeof MentorPickReviewVote>>()

const loading = ref(true) // 列表的加载中
const list = ref<MentorPickReviewSceneVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  batchId: undefined,
  isVote: undefined
})
const queryFormRef = ref() // 搜索的表单

// 投票状态选项
const voteStatusOptions = [
  { label: t('mentorPickReviewScene.voteStatus.unVote'), value: 0 },
  { label: t('mentorPickReviewScene.voteStatus.agree'), value: 1 },
  { label: t('mentorPickReviewScene.voteStatus.disagree'), value: 2 }
]

const vxeTableConfig: VxeTablePropTypes.CustomConfig = {
  storage: true,
  mode: 'drawer',
  checkMethod({ column }) {
    return !['seq', 'operator'].includes(column.field)
  }
}

const appStore = useAppStore()
const vxeTableSize = computed(() => appStore.getCurrentSizeVxe)

/** 查询列表 */
const getList = async () => {
  queryParams.batchId = batchId.value as any
  loading.value = true
  try {
    const data = await MentorPickReviewApi.getPickBatchVoteList(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  ;(queryParams as any).advanced = undefined
  handleQuery()
}

// 打开投票弹窗
const handleClick = (row: MentorPickReviewSceneVO) => {
  mentorPickReviewVoteRef.value?.open(row)
}

const batchId = ref('')
/** 初始化 **/
onMounted(() => {
  batchId.value = route.params.batchId as string
  getList()

  const table = tableRef.value
  const toolbar = toolbarRef.value
  if (table && toolbar) {
    table.connect(toolbar)
  }
})
</script>
